﻿using System;
using System.Collections.Generic;
using MadMediaManager.Core.Interfaces.Domain;

namespace MadMediaManager.Core.Interfaces.DataAccess.Repositories
{
    /// <summary>
    /// Interface using the repository pattern for data access.  
    /// Standard data access mechanisms should use this interface for this application.
    /// </summary>
    /// <typeparam name="T">The type of object the repository will hold</typeparam>
    /// <typeparam name="TId">The data type of the unique identifier for the object within the data store.</typeparam>
    public interface IRepository<T, in TId> : IDisposable where T : IEntity<TId>
    {
        /// <summary>
        /// Saves an new object to the store.
        /// </summary>
        /// <param name="entity">The object to save</param>
        void Save(T entity);

        /// <summary>
        /// Retrieves an object from the data store.
        /// </summary>
        /// <param name="id">The unique identifier of the object.</param>
        /// <returns>The object if found.</returns>
        T Get(TId id);

        /// <summary>
        /// Retrieves all <typeparamref name="T"/> from the data store.
        /// </summary>
        /// <returns>A <see cref="IList{T}"/> of the objects.</returns>
        IEnumerable<T> GetAll();

        /// <summary>
        /// Updates an object in the data store.
        /// </summary>
        /// <param name="updated">The object to update containing the new values.</param>
        void Update(T updated);

        /// <summary>
        /// Deletes an object from the data store.
        /// </summary>
        /// <param name="entity">The object to delete.</param>
        void Delete(T entity);

        /// <summary>
        /// Checks if the entity has a unique signature that does not conflict with other entities in the data store.
        /// </summary>
        /// <param name="entity">The entity to check</param>
        /// <returns>true if the entity is unique</returns>
        bool IsUnique(T entity);
    }
}
